<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form id="info">
<table border="1">
    <caption></caption>
    <thead>
    <tr>
        <th colspan="2">更新新闻内容</th>
    </tr>
    <tr>
        <th>新闻编号</th>
        <th id="id">

        </th>
    </tr>
    <tr>
        <th>新闻分类</th>
        <select id="name" name="name">
            <option></option>
        </select>
    </tr>
    <tr>
        <th>新闻标题(*)</th>
        <th><input type="text" id="title" name="title"></th>
    </tr>
    <tr>
        <th>新闻摘要</th>
        <th id="summary"><textarea id="text"></textarea></th>
    </tr>
    <tr>
        <th>作者</th>
        <th id="author"></th>
    </tr>
    <tr>
        <th colspan="2">
            <p>
                <input type="button" id="submit" value="提交">
                <input type="button" id="back" value="返回">
            </p>
        </th>
    </tr>
    </thead>
    <tbody></tbody>
    <tfoot></tfoot>
</table>
</form>

<script src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
    $(function(){
        var url = location.href;
        var param = url.substring(url.indexOf("?")+1);
        alert(param);
        $.get("news.json",
            param,
            function(data){
                for(var i=0;i<data.length;i++){
                    $("#id").val(data.newsId);
                    $("#title").val(data.title);
                    $("#summary").text(data.summary);
                    $("#author").val(data.author);
                    var str="<option>"+data.catagoryName+"</option>";
                    $("#name").append(str);
                }},
            "json");

        //更新
        $("#submit").click(function(){
            if($("#title").val()!=null && $("#title").val()!=""){
                $.get("/updateNews.do",$("#info").serialize(),function(data){
                    alert(data);
                },"text");
            }else{
                alert("新闻标题不能为空！");
            }
        });


    });
</script>


</body>
</html>